﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CoreHelper.Validation.Validators
{
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
    public class DateISOValidatorAttribute : RegexValidatorAttribute
    {
        public DateISOValidatorAttribute() : this(ValidationUtils.Messages.DateISO)
        {
        }
        public DateISOValidatorAttribute(string errorMessage) : base(ValidationUtils.RegexPatterns.DateISO, errorMessage)
        {
        }


        public override bool IsValid(object value)
        {
            if (value == null) return false;
            if (value is DateTime? || value is DateTime) return true;
            return base.IsValid(value);
        }
    }
}
